package user.web.exception;


import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import lombok.extern.slf4j.Slf4j;
import user.web.base.BaseController;
import user.web.base.BaseResp;

@Slf4j
@RestControllerAdvice()
public class GlobalExceptionHandler extends BaseController {

    @ExceptionHandler(value = ErrorCodeException.class)
    public BaseResp exceptionHandler(ErrorCodeException exception) {

        return failure(exception.getCode(), exception.getMessage());
    }
    
    @ExceptionHandler(Throwable.class)
    public BaseResp handle(Throwable ex) {
        log.error("{}", ex);
        return failure(500);
    }
    
}
